package de.dubiel.plung.client.mvp;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;

import de.dubiel.plung.client.gin.ClientGinjector;
import de.dubiel.plung.client.pages.account.AccountActivity;
import de.dubiel.plung.client.pages.account.AccountPlace;
import de.dubiel.plung.client.pages.game.GameActivity;
import de.dubiel.plung.client.pages.game.GamePlace;
import de.dubiel.plung.client.pages.start.StartActivity;
import de.dubiel.plung.client.pages.start.StartPlace;

public class AppActivityMapper implements ActivityMapper {

    private final ClientGinjector clientFactory;

    /**
     * AppActivityMapper associates each Place with its corresponding
     * {@link Activity}
     * 
     * @param clientFactory
     *            Factory to be passed to activities
     */
    public AppActivityMapper(ClientGinjector clientFactory) {
        super();
        this.clientFactory = clientFactory;
    }

    /**
     * Map each Place to its corresponding Activity. This would be a great use
     * for GIN.
     */
    @Override
    public Activity getActivity(Place place) {
        // This is begging for GIN
        if (place instanceof GamePlace)
            return new GameActivity((GamePlace) place, clientFactory);
        else if (place instanceof AccountPlace)
            return new AccountActivity((AccountPlace) place, clientFactory);
        else if (place instanceof StartPlace)
            return new StartActivity((StartPlace) place, clientFactory);

        return null;
    }

}
